package Year22_Month06.day06;

import java.util.LinkedList;
import java.util.Queue;

public class 二叉树的最大深度_BFS {
    public int maxDepth(TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        if(root == null){
            return 0;
        }
        queue.offer(root);
        int count = 0;
        while(!queue.isEmpty()){
            count++;
            int size = queue.size();
            while(size-- > 0){
                TreeNode node = queue.poll();
                if(node.left != null){
                    queue.offer(node.left);
                }
                if(node.right != null){
                    queue.offer(node.right);
                }
            }
        }
        return count;
    }
}
